package com.design.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.design.blog.model.Article;
import com.design.blog.model.vo.ArticleParams;
import com.design.blog.model.vo.CommentParams;
import com.design.blog.model.vo.PageParams;
import com.design.blog.model.R;
import com.design.blog.service.impl.ArticleServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author hxg
 * @version 1.0
 * @date 2022/2/28 23:15
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Resource
    private ArticleServiceImpl articleServiceImpl;

    @PostMapping("/getAllArticle")
    public R getArticlePage(@RequestBody PageParams params){
        return R.success(articleServiceImpl.getArticles(params));
    }

    @GetMapping("/getRecommendArticle")
    public R getRecommendArticle(){
        return R.success(articleServiceImpl.getRecommendArticle());
    }

    @PostMapping("/searchArticle")
    public R getSearchArticle(@RequestBody PageParams params){
        if (params.getSearchVal().equals("")) {
            return R.success("");
        }
        return R.success(articleServiceImpl.getSearchArticle(params.getSearchVal()));
    }

    @PostMapping("/getHotArticle")
    public R getHotArticle(){
        return R.success(articleServiceImpl.getHotArticles());
    }

    @PostMapping("/getNewArticle")
    public R getNewArticle(){
        return R.success(articleServiceImpl.getNewArticles());
    }

    @GetMapping("/view/{id}")
    public R getDetail(@PathVariable("id") Long id){
        return R.success(articleServiceImpl.getArticleById(id));
    }

    @PostMapping("/publish")
    public R publishArticle(@RequestHeader("Authorization") String token,
                            @RequestBody ArticleParams articleParams){
        return R.success(articleServiceImpl.publishArticle(token,articleParams));
    }

    @GetMapping("/like/{id}")
    public R likeArticle(@PathVariable("id") String id){
        return R.success(articleServiceImpl.likeArticle(id));
    }

}
